import java.util.*;

/**
 * @Author 12629
 * @Date 2022/3/31 21:03
 * @Description：
 */
class Person {

}
public class TestDemo2 {

    public static void main(String[] args) {
        int[] array = new int[10_0000];
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(1_0000);
        }
        HashMap<Integer,Integer> map = new HashMap<>();

        for (int i = 0; i < array.length; i++) {
            if(map.get(array[i]) == null) {
                map.put(array[i],1);
            }else {
                int val = map.get(array[i]);
                map.put(array[i],val+1);
            }
        }
        System.out.println(map);

    }

    public int numJewelsInStones(String jewels, String stones) {
        HashSet<Character> set = new HashSet<>();
        for(char ch : jewels.toCharArray()) {
            set.add(ch);
        }
        int count = 0;
        for(char ch : stones.toCharArray()) {
            if(set.contains(ch)) {
                count++;
            }
        }
        return count;
    }

    public static void main6(String[] args) {
        int[] array = new int[10_0000];
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(1_0000);
        }

        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            set.add(array[i]);
        }
        System.out.println(set);
    }

    public static void main5(String[] args) {
        Map<Person,String> map = new TreeMap<>();
        map.put(new Person(),"hello");
        map.put(new Person(),"abc");
        System.out.println(map);
    }

    public static void main3(String[] args) {
        //非常大的特点：不重复
        Set<String> set = new HashSet<>();
        set.add("hello");
        set.add("hello");
        set.add("hello");
        set.add("hello");
        set.add("hello");
        set.add("bit");
        System.out.println(set);

        List<String> list = new ArrayList<>();
        list.add("aabcd");
        list.add("aabcde");

        set.addAll(list);

        System.out.println(set);

    }

    public static void main2(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("bit",2);
        //map.put("bit",9999);
        map.put("hello",3);
        map.put("abcd",5);
        System.out.println("输出："+map);

        //集合
        Set<String> set = map.keySet();
        System.out.println(set);

        Collection<Integer> collection = map.values();
        System.out.println("collection"+collection);

        System.out.println("=================");

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for (Map.Entry<String,Integer> entry  : entrySet ) {
            System.out.println("key: " +entry.getKey()+" value: " + entry.getValue());
        }

        System.out.println("====================");
        Set<Map.Entry<String,Integer>> entrySet2 = map.entrySet();
        Iterator<Map.Entry<String,Integer>> it = entrySet2.iterator();
        while (it.hasNext()) {
            Map.Entry<String,Integer> entry = it.next();
            System.out.println("key: " +entry.getKey()+" value: " + entry.getValue());
        }

        System.out.println("todo: 去查询遍历map的方式：5种");
     }

    public static void main1(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("bit",2);
        //map.put("bit",9999);
        map.put("hello",3);
        map.put("abcd",5);
        //map.put(null,null);//TreeMap不能存null

        Integer val = map.get("hello2");//inValue();
        Integer val2 = map.getOrDefault("hello2",9);
        System.out.println(val);

        System.out.println(val2);

        Integer val3 = map.remove(null);
        System.out.println("val3 "+val3);

        System.out.println(map);

        HashMap<String,Integer> map2 = new HashMap<>();


    }
}
